<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>价值投资推荐</title>
    <link rel="stylesheet" href="../../assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../assets/module/admin.css?v=318"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        #xTable2 + .layui-table-view .layui-table-click, #xTable2 + .layui-table-view .layui-table-hover, #xTable2 + .layui-table-view .layui-table tbody tr:hover {
            background: transparent;
        }
    </style>
</head>
<body>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">

            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form toolbar">
                        <div class="layui-form-item text-right">
                            <div class="layui-inline pull-left">
                                <button class="layui-btn icon-btn" id="addStockDetail"><i
                                        class="layui-icon">&#xe654;</i>添加
                                </button>
                                <button id="file-btn-upload" class="layui-btn layui-btn layui-btn-normal icon-btn">
                                    <i class="layui-icon">&#xe681;</i>导入
                                </button>
                                <button class="layui-btn layui-btn-danger icon-btn"><i
                                        class="layui-icon">&#xe640;</i>删除
                                </button>
                            </div>

                            <div id="file-list-group" class="layui-hide"><input type="file" id="importStockExcel"></div>
                            <div class="layui-inline">
                                <input tb-search="xTable1" class="layui-input icon-search" type="text"/>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-btn-group">
                                    <button tb-export="xTable1" class="layui-btn layui-btn-primary icon-btn">
                                        <i class="layui-icon">&#xe67d;</i>
                                    </button>
                                    <button tb-refresh="xTable1" class="layui-btn layui-btn-primary icon-btn">
                                        <i class="layui-icon">&#xe9aa;</i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <table id="xTable1" lay-filter="xTable1"></table>
                </div>

            </div>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body text-danger">
            表格扩展tableX模块还封装了导出xlsx格式的excel数据、绑定行鼠标右键、post方式下载文件(支持传参数，可用于请求后端导出excel下载)等实用功能。
        </div>
    </div>
</div>

<!-- 表格状态列 -->
<script type="text/html" id="tableState">
    <input type="checkbox" lay-filter="ckState" value="{{d.userId}}" lay-skin="switch"
           lay-text="正常|锁定" {{d.state==0?'checked':''}}/>
    <!-- export-show用于前端搜索和导出数据使用 -->
    <div class="export-show">{{d.state==0?'正常':'锁定'}}</div>
</script>

<!-- js部分 -->
<script type="text/javascript" src="../../assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="../../assets/js/common.js?v=318"></script>
<script>
    layui.use(['layer', 'element', 'util', 'table', 'tableX', 'format', 'admin', 'upload', 'fileChoose'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var element = layui.element;
        var util = layui.util;
        var table = layui.table;
        var tableX = layui.tableX;
        var format = layui.format;
        var admin = layui.admin;
        var upload = layui.upload;
        var fileChoose = layui.fileChoose;

        // 前端分页
        var table1 = tableX.renderFront({
            elem: '#xTable1',
            url: '/valueRecommend/queryStockDetailsByCondition',
            page: {groups: 10},
            async:false,
            cellMinWidth: 100,
            title: '个股报告期指标',
            cols: [[
                {type: 'checkbox'},
                {field: 'stockCode', title: '股票代码', sort: false},
                {field: 'stockName', title: '股票名称', sort: false},
                {
                    field: 'reportTime', templet: function (d) {
                        return util.toDateString(d.reportTime);
                    }, title: '报告时间', sort: true
                },
                {field: 'pe', title: '市盈率', sort: true},
                {field: 'pb', title: '市净率', sort: true},
                {field: 'price', title: '价格', sort: true},
                {field: 'industryName', title: '行业名称', sort: true}
            ]]
        });


        // 上传
        upload.render({
            elem: '#file-btn-upload',
            url: '/valueRecommend/importStockInfo',   // 上传文件的url
            accept: 'file',
            before: function (obj) {
                // //预读本地文件示例，不支持ie8
                // obj.preview(function (index, file, result) {
                //     $('#importStockExcel').attr('src', result); //图片链接（base64）
                // });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code < 0) {
                    return layer.msg('上传失败');
                }else if(res.code >= 0){  //上传成功
                    return layer.msg('上传成功');
                }
                table1.reload('xTable1', {   // 按表单设置的参数请求表格接口，从第一页重新加载展示
                    url: '/valueRecommend/queryStockDetailsByCondition',
                    method: "get"
                });

            }
            , error: function () {
                // 演示失败状态，并实现重传
                var importStockExcel = $('#importStockExcel');
                importStockExcel.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                importStockExcel.find('.demo-reload').on('click', function () {
                    upload.upload();
                });
            }
        });

        // 弹窗选择
        $('#file-btn-choose').click(function () {
            fileChoose.open({
                fileUrl: '',
                listUrl: '',
                num: 1,   // 最多选择的文件数
                dialog: {
                    offset: '60px'
                },
                onChoose: function (urls) {
                    layer.msg('你选择了：' + JSON.stringify(urls), {icon: 1});
                }
            });
        });





        // 添加股票信息
        $('#addStockDetail').on('click', function () {
            var layIndex = admin.open({
                type: 2,
                title: '添加股票数据',
                content: 'userForm.html',
                end: function () {  // 监听弹窗关闭
                    if (admin.getLayerData(layIndex, 'formOk')) {  // 判断表单操作成功标识
                        table1.reload();  // 成功刷新表格
                    }
                }
            });
        });


        setTimeout(function () {
            table.resize('xTable1');
        }, 200);

    });
</script>
</body>
</html>
